package com.ruoyi.yjgl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yjgl.domain.TbYjglYjsz;
import com.ruoyi.yjgl.service.ITbYjglYjszService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预警设置Controller
 *
 * @author ruoyi
 * @date 2023-11-11
 */
@RestController
@RequestMapping("/yjgl/yjsz")
public class TbYjglYjszController extends BaseController
{
    @Autowired
    private ITbYjglYjszService tbYjglYjszService;

    /**
     * 查询预警设置列表
     */
    @PreAuthorize("@ss.hasPermi('yjgl:yjsz:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbYjglYjsz tbYjglYjsz)
    {
        startPage();
        List<TbYjglYjsz> list = tbYjglYjszService.selectTbYjglYjszList(tbYjglYjsz);
        return getDataTable(list);
    }

    /**
     * 导出预警设置列表
     */
    @PreAuthorize("@ss.hasPermi('yjgl:yjsz:export')")
    @Log(title = "预警设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbYjglYjsz tbYjglYjsz)
    {
        List<TbYjglYjsz> list = tbYjglYjszService.selectTbYjglYjszList(tbYjglYjsz);
        ExcelUtil<TbYjglYjsz> util = new ExcelUtil<TbYjglYjsz>(TbYjglYjsz.class);
        util.exportExcel(response, list, "预警设置数据");
    }

    /**
     * 获取预警设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('yjgl:yjsz:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbYjglYjszService.selectTbYjglYjszById(id));
    }

    /**
     * 新增预警设置
     */
    @PreAuthorize("@ss.hasPermi('yjgl:yjsz:add')")
    @Log(title = "预警设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbYjglYjsz tbYjglYjsz)
    {
        return toAjax(tbYjglYjszService.insertTbYjglYjsz(tbYjglYjsz));
    }

    /**
     * 修改预警设置
     */
    @PreAuthorize("@ss.hasPermi('yjgl:yjsz:edit')")
    @Log(title = "预警设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbYjglYjsz tbYjglYjsz)
    {
        return toAjax(tbYjglYjszService.updateTbYjglYjsz(tbYjglYjsz));
    }

    /**
     * 删除预警设置
     */
    @PreAuthorize("@ss.hasPermi('yjgl:yjsz:remove')")
    @Log(title = "预警设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbYjglYjszService.deleteTbYjglYjszByIds(ids));
    }
}
